package com.yisu.expressway.weather.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yisu.expressway.R;
import com.yisu.expressway.weather.model.SuggestionObj;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/5 0005.
 */

public class LifeSuggestionAdapter extends  RecyclerView.Adapter<LifeSuggestionAdapter.SuggestionViewHolder>  {

    ArrayList<SuggestionObj> mData = new ArrayList<>();
    private Context mContext;

    public LifeSuggestionAdapter(Context context){
        this.mContext = context;
    }

    public void setData(ArrayList<SuggestionObj> list){
        this.mData = list;
        notifyDataSetChanged();
    }


    @Override
    public SuggestionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.life_suggest_item, parent, false);
        return new SuggestionViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(SuggestionViewHolder holder, int position) {
        if(mData.size() <= position ){
            return;
        }

        final SuggestionObj item = mData.get(position);
        holder.mTv_title.setText(item.title);
        holder.mTv_des.setText(item.brief);
        holder.mIv_icon.setImageResource(item.iconResId);
        Log.d("OMG","==item.brief==" + item.brief);
        
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 :mData.size();
    }

    class SuggestionViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_suggest_title) TextView mTv_title;
        @Bind(R.id.iv_type) ImageView mIv_icon;
        @Bind(R.id.tv_suggest_des) TextView mTv_des;

        public SuggestionViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
